package io.sage.modules.camera.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.sage.modules.camera.entity.BMonitorCamera;
import io.sage.modules.camera.entity.BMonitorCamersHistory;
import io.sage.modules.camera.service.BMonitorCamersHistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.sage.common.utils.PageUtils;
import io.sage.common.utils.R;



/**
 * 摄像头拍照和摄像纪律页面
 *
 * @author zhang
 * @email ${email}
 * @date 2019-08-12 16:51:36
 */
@RestController
@RequestMapping("basics/bmonitorcamershistory")
public class BMonitorCamersHistoryController {
    @Autowired
    private BMonitorCamersHistoryService bMonitorCamersHistoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("basics:bmonitorcamershistory:list")
    public R list(@RequestParam Map<String, Object> params){
        //PageUtils page = bMonitorCamersHistoryService.queryPage(params);
        Integer pageSize = 0;
        if (params != null && params.get("limit") != null) {
            pageSize = Integer.parseInt(params.get("limit").toString());
        }
        Integer pageNum = 10;
        if (params != null && params.get("page") != null) {
            pageNum = Integer.parseInt(params.get("page").toString());
        }
        HashMap<String, Object> paramMap = new HashMap<String, Object>();
        if(params.get("createUser")!=null){
            if(!"".equals(params.get("createUser").toString())){
                paramMap.put("createUser", params.get("createUser").toString());
            }
        }
        if(params.get("cameraId")!=null){
            if(!"".equals(params.get("cameraId").toString())){
                paramMap.put("cameraId", params.get("cameraId").toString());
            }
        }
        params.put("orderby", "h.create_time");
        params.put("isDel", 0);
        PageHelper.startPage(pageNum, pageSize);

        List<BMonitorCamersHistory> monitorCameraList  = bMonitorCamersHistoryService.selectByMap(paramMap);

        PageInfo<BMonitorCamersHistory> pageInfo = new PageInfo<BMonitorCamersHistory>(monitorCameraList);
        return R.ok().put("page", pageInfo);
       // return R.ok().put("page", null);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("basics:bmonitorcamershistory:info")
    public R info(@PathVariable("id") Integer id){
        BMonitorCamersHistory bMonitorCamersHistory = bMonitorCamersHistoryService.queryById(id);

        return R.ok().put("bMonitorCamersHistory", bMonitorCamersHistory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("basics:bmonitorcamershistory:save")
    public R save(@RequestBody BMonitorCamersHistory bMonitorCamersHistory){
        bMonitorCamersHistoryService.insert(bMonitorCamersHistory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("basics:bmonitorcamershistory:update")
    public R update(@RequestBody BMonitorCamersHistory bMonitorCamersHistory){
        bMonitorCamersHistoryService.update(bMonitorCamersHistory);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("basics:bmonitorcamershistory:delete")
    public R delete(@RequestBody Integer[] ids){
        bMonitorCamersHistoryService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
